package com.ruoyi.web.controller.material;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.material.domain.SmesMaterialStockDetail;
import com.ruoyi.mes.material.service.ISmesMaterialStockDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 原料出入库Controller
 *
 * @author simpsense
 * @date 2020-12-15
 */
@RestController
@RequestMapping("/material/materialOutInDetail")
public class SmesMaterialStockDetailController extends BaseController
{
    @Autowired
    private ISmesMaterialStockDetailService smesMaterialStockDetailService;

    /**
     * 查询原料出入库列表
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesMaterialStockDetail smesMaterialStockDetail)
    {
        startPage();
        List<SmesMaterialStockDetail> list = smesMaterialStockDetailService.selectSmesMaterialStockDetailList(smesMaterialStockDetail);
        return getDataTable(list);
    }

    /**
     * 导出原料出入库列表
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:export')")
    @Log(title = "原料出入库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesMaterialStockDetail smesMaterialStockDetail)
    {
        List<SmesMaterialStockDetail> list = smesMaterialStockDetailService.selectSmesMaterialStockDetailList(smesMaterialStockDetail);
        ExcelUtil<SmesMaterialStockDetail> util = new ExcelUtil<SmesMaterialStockDetail>(SmesMaterialStockDetail.class);
        return util.exportExcel(list, "materialOutInDetail");
    }

    /**
     * 获取原料出入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:query')")
    @GetMapping(value = "/{rowId}")
    public AjaxResult getInfo(@PathVariable("rowId") Long rowId)
    {
        return AjaxResult.success(smesMaterialStockDetailService.selectSmesMaterialStockDetailById(rowId));
    }

    /**
     * 新增原料出入库
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:add')")
    @Log(title = "原料出入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesMaterialStockDetail smesMaterialStockDetail)
    {
        return toAjax(smesMaterialStockDetailService.insertSmesMaterialStockDetail(smesMaterialStockDetail));
    }

    /**
     * 修改原料出入库
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:edit')")
    @Log(title = "原料出入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesMaterialStockDetail smesMaterialStockDetail)
    {
        return toAjax(smesMaterialStockDetailService.updateSmesMaterialStockDetail(smesMaterialStockDetail));
    }

    /**
     * 删除原料出入库
     */
    @PreAuthorize("@ss.hasPermi('material:materialOutInDetail:remove')")
    @Log(title = "原料出入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rowIds}")
    public AjaxResult remove(@PathVariable Long[] rowIds)
    {
        return toAjax(smesMaterialStockDetailService.deleteSmesMaterialStockDetailByIds(rowIds));
    }
}